﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace KNXObjects.ValueObjects
{
    public class ValueObjectBase<T> : IValueObject<T>, INotifyPropertyChanged
    {
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region IValueObject<T> Members

        private T m_Value;
        public T Value
        {
            get
            {
                return m_Value;
            }
            set
            {
                if (!m_Value.Equals(value))
                {
                    m_Value = value;
                    NotifyPropertyChanged("Value");
                }
            }
        }

        #endregion

        #region IEquatable<IValueObject<T>> Members

        public virtual bool Equals(IValueObject<T> other)
        {
            return Value.Equals(other.Value);
        }

        #endregion
    }
}
